﻿#include <QDataStream>
#include <QCoreApplication>

#include "isave.h"
#include "saveprivate.h"

ISave::ISave(int version, const QString &name, bool autoLoad, bool autoSave) :
    d_ptr(new SavePrivate(version, name, autoLoad, autoSave, this))
{

}

ISave::~ISave()
{
    delete d_ptr;
}

void ISave::load()
{
    d_ptr->load();
}

void ISave::save(bool canSaveAngin)
{
    d_ptr->save();
    if (canSaveAngin == false)
    {
        d_ptr->setStopSave();
    }
}

int ISave::dataStreamVersion()
{
    return QDataStream::Qt_5_6;
}

QString ISave::dataDir()
{
    return qApp->applicationDirPath() + "/config";
}

QString ISave::saveFileName() const
{
    return d_ptr->saveFileName();
}

QString ISave::backUpFileName() const
{
    return d_ptr->backUpFileName();
}

void ISave::loadOldData(const QByteArray &saveCurrentData, int version)
{
    if (version != d_ptr->m_nVersion)
    {
        return;
    }

    QDataStream ds(saveCurrentData);
    ds.setVersion(dataStreamVersion());
    loadCurrentVersionOldData(ds);
}

QByteArray ISave::saveCurrentData()
{
    QByteArray data;
    QDataStream ds(&data, QIODevice::WriteOnly);
    ds.setVersion(dataStreamVersion());
    saveCurrentVersionCurrentData(ds);
    return data;
}

void ISave::loadCurrentVersionOldData(QDataStream &)
{

}

void ISave::saveCurrentVersionCurrentData(QDataStream &)
{

}
